<?php
class gladiator_armoury 
{

public $max_weights = 10;

  function __construct($user_info,$user_id) {
       //print "In constructor\n";
       $this->user_info = $user_info;
       $this->user_id = $user_id;
   }


function list_items ($user_id = 0, $type,$weapons_learned,$weapons_got = '')
{
 global $db,$user_info;
 
    // check if we are listing all items or just the users items
    if ($user_id == $this->user_id)
    {
        // list all weapons and highlight the ones you have then enable the equip option on the ones you have
                $sql = "SELECT * FROM `gladiator_items` WHERE `type`='$type'";
                $weapons = $db->fetch_real_array($sql);
                
                $tick = '<img src="'.URL_IMAGES.'/tick.gif" WIDTH=11 HEIGHT=11 ALIGN=bottom border=0></img>';
                
                $options = array();
                foreach ($weapons as $key => $value)
                {
                            $weapon_id = $value['id'];
                            $weapon_name = $value['name'];
                            $equip_url = ahref("/gladiator/arm/immob/$weapon_id/",'equip');
                            $learn_url = ahref("/gladiator/arm/train/$weapon_id/",'learn');
                            if (preg_match("/,$weapon_id,/i", $weapons_got) && preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person has this weapon in their inventory and has it learned
                                if ($user_info[USER_ID]['equip_weapon'] == $weapon_id || $user_info[USER_ID]['equip_armour'] == $weapon_id)
                                {
                                    $pre = '<b>';
                                    $post = '</b>';
                                    $equip_url = ahref("/gladiator/arm/immob/unequip/$type/",'un-equip');
                                }
                                else
                                {
                                    $pre = '';
                                    $post = '';
                                }
                                $options[$weapon_id] = "$pre $weapon_name $post $tick [$equip_url]";	
                           } elseif (preg_match("/,$weapon_id,/i", $weapons_got) && !preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person has this weapon in their inventory but doesn't know how to use it
                                $options[$weapon_id] = "$weapon_name $tick [$learn_url]";	
                           } elseif (!preg_match("/,$weapon_id,/i", $weapons_got) && preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person doesnt have this weapon but does know how to use it
                                $options[$weapon_id] = "<font color=grey><del>$weapon_name</del></font> $tick";	
                           } elseif (!preg_match("/,$weapon_id,/i", $weapons_got) && !preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person doesnt have this weapon and doesn't know how to use it
                                $options[$weapon_id] = "<font color=grey><del>$weapon_name</del></font> ";	
                            } else {
                                // person doesn't have this weapon
                                $options[$weapon_id] = "<font color=grey><del>$weapon_name</del></font> ";	
                            }
                }
                
                //$options['/gladiator/'] = '<b>Take me back to the main page</b>';
                echo player_options($options,1);

    }
    else
    {
        // list all weapons
                $sql = "SELECT * FROM `gladiator_items` WHERE `type`='$type'";
                $weapons = $db->fetch_real_array($sql);
                
                $options = array();
                foreach ($weapons as $key => $value)
                {
                            $weapon_id = $value['id'];
                            if (preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                $pre = '<b>'; 
                                $post = '</b> <img src="'.URL_IMAGES.'/tick.gif" WIDTH=11 HEIGHT=11 ALIGN=bottom border=0></img>';
                            } else {
                                $pre = ''; 
                                $post = '';
                            }
                            $options["/gladiator/arm/train/$weapon_id/"] = ''.$pre.$value['name'].$post.'';											
                }
                
                //$options['/gladiator/'] = '<b>Take me back to the main page</b>';
                echo player_options($options);

    }
}

    function question ($question1,$question2,$question3)
    {
        require_once(PEAR . "Numbers/Roman.php");
    
        //converting a random number between 1 and 3999 from Arabic to the Roman Numeral
        //uppercase true, html false, then back to Arabic
        $roman1 =  Numbers_Roman::toNumeral($question1,true,false);
        $roman2 =  Numbers_Roman::toNumeral($question2,true,false);
        $roman3 =  Numbers_Roman::toNumeral($question3,true,false);
        $arabic = Numbers_Roman::toNumber($roman1);
        
        $output = '<form METHOD=post  ACTION="'.URL_SELF.'">';
        $output .= 'Please enter this number in simple english: <img src="http://images.europa100ad.com/scroll.php?text='.$roman1.'"></img><input type="text" name="guess1">';
        $output .= '<BR><br>--<BR>Please enter this number in simple english:  <img src="http://images.europa100ad.com/scroll.php?text='.$roman2.'"></img><input type="text" name="guess2">';
        $output .= '<br><BR>--<BR>Please enter this number in simple english: <img src="http://images.europa100ad.com/scroll.php?text='.$roman3.'"></img><input type="text" name="guess3">';
        $output .= '<br><input type=submit value="Guess">';
        $output .= '</form>';

        return $output; 
    }

    function answer ($item_id,$question1,$question2,$question3,$answer1,$answer2,$answer3,$type)
    {
        require_once(PEAR . "Numbers/Roman.php");
        
        global $db;
    
        //converting a random number between 1 and 3999 from Arabic to the Roman Numeral
        //uppercase true, html false, then back to Arabic
        $roman1 =  Numbers_Roman::toNumeral($question1,true,false);
        $roman2 =  Numbers_Roman::toNumeral($question2,true,false);
        $roman3 =  Numbers_Roman::toNumeral($question3,true,false);
        $arabic = Numbers_Roman::toNumber($roman1);
        
        $points = 0;
        
        if ($question1 == $answer1)
        {
            $result1 = 'tick.gif';
            $points++;
        }
        else
        {
            $result1 = 'question.gif';
        }


        if ($question2 == $answer2)
        {
            $result2 = 'tick.gif';
            $points++;
        }
        else
        {
            $result2 = 'question.gif';
        }


        if ($question3 == $answer3)
        {
            $result3 = 'tick.gif';
            $points++;
        }
        else
        {
            $result3 = 'question.gif';
        }
        
        if ($points == 3)
        {
            $db->query("UPDATE `user_gladiator` SET `gladiator_items_learned` = CONCAT( gladiator_items_learned, ',$item_id,' ) WHERE `assoc_id`='".USER_ID."'");
            $message = "You have now learned how to use this $type.";
        }
        else
        {
            // Do nothing becuase user got at least 1 question wrong
            $message = 'Better luck next time!';
        }
        
        $output = "<table border=\"1\" bordercolor=\"\" width=\"300\" bgcolor=\"\">
<tr>
<td> <B>ROMAN</b> </td>
<td> <B>What you said...</b> </td>
<td> <B>Answer</b> </td>
</tr>
<tr>
<td> $roman1 </td>
<td> $answer1 </td>
<td> <img src=\"".URL_IMAGES."/$result1\" WIDTH=11 HEIGHT=11 ALIGN=bottom border=0></img> </td>
</tr>
<tr>
<td> $roman2 </td>
<td> $answer2 </td>
<td> <img src=\"".URL_IMAGES."/$result2\" WIDTH=11 HEIGHT=11 ALIGN=bottom border=0></img> </td>
</tr>
<tr>
<td> $roman3 </td>
<td> $answer3 </td>
<td> <img src=\"".URL_IMAGES."/$result3\" WIDTH=11 HEIGHT=11 ALIGN=bottom border=0></img> </td>
</tr>

</table><BR><B><pre>$message</pre></B>
";

        return $output; 
    }
    
function equip ($user_id, $item_id,$weapons_learned,$weapons_got)
{
 global $db;
 
                $sql = "SELECT * FROM `gladiator_items` WHERE `id`='$item_id'";
                $weapon_info = $db->return_first_result($sql);
                                
                            $weapon_id = $weapon_info['id'];
                            $weapon_name = $weapon_info['name'];
                            $weapon_type = $weapon_info['type'];
                            if (preg_match("/,$weapon_id,/i", $weapons_got) && preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person has this weapon in their inventory and has it learned
                                $db->query("UPDATE `user_gladiator` SET `equip_$weapon_type`='$weapon_id' WHERE `assoc_id`='$user_id'");
                                $output = "<pre>$weapon_name equipped</pre>";	
                           } elseif (preg_match("/,$weapon_id,/i", $weapons_got) && !preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person has this weapon in their inventory but doesn't know how to use it
                                $output = "<pre>$weapon_name <b>NOT</b> equipped.<BR>You must learn how to use it first.</pre>";	
                           } elseif (!preg_match("/,$weapon_id,/i", $weapons_got) && preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person doesnt have this weapon but does know how to use it
                                $output = "<pre>$weapon_name <b>NOT</b> equipped.<BR>You must acquire this item first.</pre>";	
                           } elseif (!preg_match("/,$weapon_id,/i", $weapons_got) && !preg_match("/,$weapon_id,/i", $weapons_learned)) {
                                // person doesnt have this weapon and doesn't know how to use it
                                $output = "<pre>$weapon_name <b>NOT</b> equipped.<BR>You have to own and know how to use a weapon before you can equip it!</pre>";	
                            } else {
                                // person doesn't have this weapon
                                $output = "<pre>$weapon_name <b>NOT</b> equipped.<BR>You have to own and know how to use a weapon before you can equip it!</pre>";	
                            }
                            
                 return $output;
  }


function unequip ($user_id, $item_type)
{
    global $db;
 
        $db->query("UPDATE `user_gladiator` SET `equip_$item_type`='0' WHERE `assoc_id`='$user_id'");
        $output = "<pre>$item_type un-equipped</pre>";	
        return $output;
 }
                
                
                
}
?>